package com.zhongc.advance.common.util;

import java.util.regex.Matcher;
import java.util.regex.Pattern;


/**
 * 解析el表达式 环境变量
 * 
 *                       
 * @Filename Env.java
 *
 * @Description 
 *
 * @Version 1.0
 *
 * @Author zhongc
 *
 * @Email zhong_ch@foxmail.com
 *       
 * @History 
 *<li>Author: zhongc</li>
 *<li>Date: 2015年7月24日</li>
 *<li>Version: 1.0</li>
 *<li>Content: create</li>
 *
 */
public class Env {
	
	private final static Pattern pattern = Pattern.compile("\\$\\{[^\\$]*\\}");
	
	public static String analyze(String s){
		StringBuilder builder = new StringBuilder();
		for(Matcher matcher = pattern.matcher(s); matcher.find(); matcher = pattern.matcher(s)){
			String t = matcher.group();
			int index = s.indexOf(t);
			builder.append(s.substring(0, index));
			builder.append(System.getProperty(t.substring(2, t.length() - 1), t));
			s = s.substring(index + t.length());
		}
		builder.append(s);
		return builder.toString();
	}
}
